/**
 * Created by ebalmes Oct 6, 2009 8:45:34 AM
 * 
 */
package gui.actions;

import gui.dialogs.BasicDialog;
import gui.dialogs.CreatePatientDialog;
import gui.dialogs.OpenDialog;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JMenuItem;

import model.DataModel;

public class ActionFactory {
	public static XAction getOpenPatientDialogAction(final JFrame owner) {
		return new XAction("Open patient...", null, "Open patient...",
				KeyEvent.VK_O) {
			OpenDialog dialog = new OpenDialog("Open patient", owner);

			@Override
			public void actionPerformed(ActionEvent e) {
				dialog.setVisible(true);
			}
		};
	}

	public static XAction getExitAppAction() {
		return new XAction("Quit", null, "Quit", KeyEvent.VK_Q) {

			@Override
			public void actionPerformed(ActionEvent e) {
				System.exit(-1);
			}
		};
	}

	public static XAction getSaveAction() {
		return new XAction("Save", null, "Save all data", KeyEvent.VK_S) {

			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					DataModel.getInstance().save();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}

		};
	}

	public static XAction getDialogOkAction(final BasicDialog dialog) {
		return new XAction("OK", null, "OK", KeyEvent.VK_O) {

			@Override
			public void actionPerformed(ActionEvent e) {
				dialog.OK();
			}
		};
	}

	public static XAction getCloseDialogAction(final BasicDialog dialog) {
		return new XAction("Close", null, "Close the dialog", KeyEvent.VK_C) {

			@Override
			public void actionPerformed(ActionEvent e) {
				dialog.setVisible(false);
			}
		};
	}

	public static XAction getHelpAction() {
		return new XAction("Help", null, "Open the help", KeyEvent.VK_H) {

			@Override
			public void actionPerformed(ActionEvent e) {

			}
		};
	}

  public static XAction getCreatePatientDialog(final JFrame owner) {
    return new XAction("New patient...", null, "New patient...",
        KeyEvent.VK_N) {
      BasicDialog dialog = new CreatePatientDialog("Create new patient", owner);

    @Override
    public void actionPerformed(ActionEvent e) {
        dialog.setVisible(true);
    }
};
  }
}
